#include "PanelLayer.h"
#include "GameScene.h"
#include "StaticData.h"
#include "GoldCounterLayer.h"
#include "ScheduleCountDown.h"

using namespace cocos2d;
PanelLayer::PanelLayer()
	:_goldCounterLayer(0)
{
}

PanelLayer::~PanelLayer()
{
}

bool PanelLayer::init()
{
	if(CCLayer::init()){
		CCSize winSize=CCDirector::sharedDirector()->getWinSize();
		CCSprite* pauseSprite=CCSprite::createWithSpriteFrameName(StaticData::getInstance()->stringFromKey("pause_normal"));
		CCMenuItemSprite* pauseItem=CCMenuItemSprite::create(pauseSprite,pauseSprite,this,menu_selector(PanelLayer::pause));
		CCMenu* menu=CCMenu::create(pauseItem,0);
		addChild(menu);
		CCSize pauseSize=pauseItem->getContentSize();
		menu->setPosition(winSize.width-pauseSize.width*0.5,pauseSize.height*0.5);

		_goldCounterLayer=GoldCounterLayer::create();
		addChild(_goldCounterLayer);
		_goldCounterLayer->setPosition(winSize.width*0.05,winSize.height*0.05);

		float fontSize=16;
		ScheduleCountDown* countDown=ScheduleCountDown::create(this);
		_scheduleLabel=CCLabelTTF::create("60","Thonburi",fontSize);
		_scheduleLabel->addChild(countDown);
		addChild(_scheduleLabel);
		_scheduleLabel->setPosition(CCPoint(winSize.width*0.3,winSize.height*0.05));
		return true;
	}
	return false;
}

void PanelLayer::pause(cocos2d::CCObject* sender)
{
	GameScene* gameScene=static_cast<GameScene*>(getParent());
	gameScene->pause();
}

void PanelLayer::scheduleTimeUp()
{
	GameScene* gameScene=static_cast<GameScene*>(getParent());
	gameScene->scheduleTimeUp();
}

void PanelLayer::setScheduleNumber(int number)
{
	_scheduleLabel->setString(CCString::createWithFormat("%d",number)->getCString());
}
